﻿using OA.Model.MyAttribute;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
//using System.Web.DynamicData;

namespace OA.Model
{
    //[TableName("知识表")]
    [Table("Knowledge")]
    public class Knowledge : BaseInfo
    {
        public int Status { get; set; }

        /// <summary>
        ///  知识类型
        /// </summary>
       // [Index("KnowledgeGroup")]
        [Display(Name = "类型")]
        [Tag(TagEnum.Select, "required", "类型", "")]
        public int GroupID { get; set; }

        [NotMapped]
        public string GroupName { get; set; }

        [MaxLength(50)]
        [Display(Name = "标题")]
        [Tag(TagEnum.Text, "required", "标题", 2, 50)]
        [Required]
        public string Title { get; set; }

        [Display(Name = "作者")]
        [Tag(TagEnum.Text, "required", "作者", 2, 50)]
        public string Author { get; set; }

        [MaxLength(1000)]
        [Display(Name = "内容")]
        [Tag(TagEnum.TextArea, "", "内容", 2, 1000)]
        public string Content { get; set; }

        /// <summary>
        /// 置顶
        /// </summary>
        [Display(Name = "置顶")]
        [Tag(TagEnum.Switch, "required", "置顶", 2, 20)]
        public bool IsTop { get; set; }        
    }


    public class SimpleKnowledge : SimpleInfo
    {
        public string Title { get; set; }

        public int GroupID { get; set; }

        public string GroupName { get; set; }

        public string Author { get; set; }

        public string Content { get; set; }

        public string Attachment { get; set; }

        public bool IsTop { get; set; }

        public static Expression<Func<Knowledge, SimpleKnowledge>> Map = m => new SimpleKnowledge()
        {
            ID = m.ID,
            Title = m.Title,
            GroupID = m.GroupID,
            Author = m.Author,
            Content = m.Content,
            IsTop = m.IsTop,
            Status = m.Status
        };
    }
}
